<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>vue生命周期</h1>
    <div id = "app">
        {{ name }}
        <button @click="updateName">更新</button>
        <button @click="destroy">销毁</button>
      </div>
</body>
<script src="../js/vue.js"></script>
<script>
    var vm = new Vue({
        el: '#app',
        data: {
            name: 'lanlang'
        },
        methods: {
            updateName(){
                console.log("修改名称");
                this.name = "蓝狼" 
            },
            destroy(){
                vm.$destroy
            }
        },
        beforeCreate(){
            console.log(`beforeCreate: ${this.name}`);   // undefined
        },
        created(){
            console.log(`created: ${this.name}`);  // lanlang
        },
        beforeMount(){
            console.log(`beforeMount: ${this.name}`);  // lanlang
        },
        mounted(){
            console.log(`mounted: ${this.name}`);  // lanlang
        },
        // 点击操作会进行触发
        beforeUpdate(){
            console.log(`beforeUpdate: ${this.name}`);
        },
        updated(){
            console.log(`updated: ${this.name}`);
        },
        // 点击销毁按钮后会先触发 beforeDestroy
        beforeDestroy(){
            console.log(`beforeDestroy: ${this.name}`);
        },
        destroyed(){
            console.log(`destroyed: ${this.name}`);
            // 在这之后点击页面 更新 按钮将无任何效果
        },

    })
</script>
</html>